<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
<%@ include file="../header.jsp"%>

<div class="content-wrapper" style="font-family: '微软雅黑';">
	<input type="hidden" id="ctx" value="<%=request.getContextPath()%>" />
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<h1>
			${module } <small>Control panel</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href=""><i class="fa fa-dashboard"></i>主页</a></li>
			<li class="active">广告列表</li>
		</ol>
	</section>
	<!-- Main content -->
	<section class="content">
		<div class="row">
			<div class="col-xs-12">
				<div class="box">
					<div class="box-header">
						<div>
							<div>
								提交开始时间： <input type="text" id="start_time" /> 提交结束时间： <input
									type="text" id="end_time" /> 城市： <input type="text"
									id="cityName" />
								关键字：<input type="text" id="keyCode" /> 
								<input type="button" class="btn btn-success" style="width: 100px;" onclick="search1()" value="查询">
								&nbsp;&nbsp;&nbsp;&nbsp;
								<a type="button" class="btn btn-success" style="width: 100px;" href='<c:url value="/advert/new"/>'>添加广告</a>
							</div>
						</div>
					</div>
					<!-- /.box-header -->
					<div class="box-body">
						<table id="example" class="display">
							<thead>
								<tr style="background-color: #97CBFF; color: white">
									<th>描述</th>
									<th>类型</th>
									<th>状态</th>
									<th>图片</th>
									<th>开始时间</th>
									<th>结束时间</th>
									<th>地区</th>
									<th>原价</th>
									<th>折后价</th>
									<th>操作</th>
								</tr>
							</thead>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
				<!-- /.box -->
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
		<!--  显示下面的分页控件  -->
	</section>
	<!-- /.content -->
</div>
<jsp:include page="../js.jsp" />
<%@ include file="../footer.jsp"%>
<script type="text/javascript">
	$('#start_time').datetimepicker({
		lang : 'ch',
		timepicker : true
	});
	$('#end_time').datetimepicker({
		lang : 'ch',
		timepicker : true
	});

	var table;
	$(document)
			.ready(
					function() {
						var u = '<c:url value="/advert/edit?advertid="/>';
						table = $('#example')
								.DataTable(
										{
											"pagingType" : "simple_numbers",//设置分页控件的模式  
											searching : false,//屏蔽datatales的查询框  
											aLengthMenu : [ 10, 50, 100 ],//设置一页展示10条记录  
											"bLengthChange" : true,//屏蔽tables的一页展示多少条记录的下拉列表  
											"oLanguage" : { //对表格国际化  
												"sLengthMenu" : "每页显示 _MENU_条",
												"sZeroRecords" : "没有找到符合条件的数据",
												//  "sProcessing": "&lt;img src=’./loading.gif’ /&gt;",    
												"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
												"sInfoEmpty" : "木有记录",
												"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
												"sSearch" : "搜索：",
												"oPaginate" : {
													"sFirst" : "首页",
													"sPrevious" : "前一页",
													"sNext" : "后一页",
													"sLast" : "尾页"

												}
											},
											"processing" : true, //打开数据加载时的等待效果  
											"serverSide" : true,//打开后台分页  
											"ajax" : {
												"url" : '<c:url value="/advert/list/data"/>',
												"dataSrc" : "aaData",
												"type": "POST",
												"data" : function(d) {
													var start_time = $('#start_time').val();
													var end_time = $('#end_time').val();
													var keyCode = $('#keyCode').val();
													var cityName = $('#cityName').val();
													//添加额外的参数传给服务器  
													d.starttime = start_time;
													d.endtime = end_time;
													d.keyCode = keyCode;
													d.cityName = cityName;	
												}

											},
											"columns" : [
													{
														"data" : "descption"
													},
													{
														"data" : function(obj) {
															if (obj.type == 2) {
																return "推广";
															} else if (obj.type == 1) {
																return "指定商品广告";
															} else if(obj.type==3){
																return "未指定商品广告";
															}
														}
													},
													{
														"data" : function(obj) {
															if (obj.status == 0) {
																return "已禁用";
															} else if (obj.status == 1) {
																return "使用中";
															}
														}
													},
													{
														"data" : function(obj){
															if(obj.picpath){
																return "<img style='width:188px;height:63px;' src='"+obj.picpath+"@188w' />";
															}
															return "";
														}
													},
													{
														"data" : "starttime"
													},
													
													{
														"data" : "endtime"
													},
													{
														"data" :"cityname"
													},
													{
														"data" : "originalPrice"
													},
													{
														"data" : "discountPrice"
													},
													{
														"data" : function(obj) {
															if(obj.advertid){
																return "<a href='"+u+obj.advertid+"'>编辑</a>&nbsp;&nbsp;&nbsp;"+
																"<a href='javascript:void(0)' onclick='deleteAdvert("+obj.advertid+")'>删除</a>";
															}
															return "";
														}
													} ]

										});
					});

	function search1() {
		table.ajax.reload();
	}

	function deleteAdvert(id){
		var u = '<c:url value="/advert/delete?advertid="/>';
		swal({   
			title: "确定删除?",   
			text: "删除后将无法回复!",   
			type: "warning",   
			showCancelButton: true,   
			confirmButtonColor: "#DD6B55",   
			confirmButtonText: "确定删除!",   
			cancelButtonText: "取消!",   
			closeOnConfirm: false,   
			closeOnCancel: true }, 
			function(isConfirm){   
				if (isConfirm) {
					$.post(u+id,{},function(data){
						if(data.code==0){
							table.ajax.reload();
							swal("已删除!", "该广告已成功删除", "success");  
						}
					},"json");
				} 
			});
	}
	
	function auditPass(id) {
		var localhostPaht = $("#ctx").val();
		// 调用审核方法
		$.post(localhostPaht + "/broker/withdraw/allow", {
			withdrawids : id
		}, function(data) {
			table.ajax.reload();
		});
	}
</script>
</body>
</html>





